
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:insert="~{common/header :: head}"></th:block>
    <title th:text="${'欢迎'+sectionName+@environment.getProperty('site.main.titleInfo')}"></title>
</head>
<body>

<div th:insert="~{common/header :: nav}"></div>

<div class="layui-container fly-marginTop">
    <div class="fly-panel fly-panel-user" pad20>
        <div class="layui-tab layui-tab-brief" lay-filter="user">
            <ul class="layui-tab-title">
                <li th:if="${section=='login'}" onclick="javascript:setType(3)" class="layui-this">密码登录</li>
                <li onclick="javascript:setType(2)" th:class="${section=='register'?'layui-this':''}" th:text="${'邮箱'+sectionName}"></li>
                <li th:if="${0!=smsEnable}" onclick="javascript:setType(1)" th:text="${'手机'+sectionName}"></li>

                <li th:if="${section=='login'}" class="html5plus-hide layui-hide-xs" onclick="javascript:alertQrcode()">扫码登录</li>
            </ul>
            <div class="layui-form layui-tab-content" id="LAY_ucm" style="padding: 20px 0;">
                <div th:if="${section=='login'}" class="layui-tab-item layui-show">
                    <div class="layui-form layui-form-pane">
                        <div class="layui-form-item">
                            <label for="phoneorMail" class="layui-form-label">手机/邮箱</label>
                            <div class="layui-input-inline">
                                <input type="text" id="phoneorMail" name="phoneorMail" required lay-verify="required" placeholder="请输入您的手机号或邮箱号" class="layui-input">
                            </div>
                            <div class="layui-form-mid layui-word-aux">使用第三方账号注册的用户需先绑定手机/邮箱号</div>
                        </div>
                        <div class="layui-form-item">
                            <label for="password" class="layui-form-label">密码</label>
                            <div class="layui-input-inline">
                                <input type="password" id="password" name="password" required lay-verify="required" autocomplete="off" class="layui-input" placeholder="请输入6到16位的密码">
                            </div>
                            <div class="layui-form-mid layui-word-aux">如果您之前未设置过密码，请使用其它方式登陆后在账户中心设置密码</div>
                        </div>
                    </div>
                </div>
                <div th:class="${section=='register'?'layui-tab-item layui-show':'layui-tab-item'}">
                    <div class="layui-form layui-form-pane">
                            <div class="layui-form-item">
                                <label for="mail" class="layui-form-label">邮箱号</label>
                                <div class="layui-input-inline">
                                    <input type="text" id="mail" name="mail" required lay-verify="email" autocomplete="off" class="layui-input" placeholder="请输入您的邮箱号">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label for="verifyCode" class="layui-form-label">验证码</label>
                                <div class="layui-input-inline">
                                    <input type="text" id="verifyCode" name="verifyCode" required lay-verify="required" autocomplete="off" class="layui-input" placeholder="请先点击下方人机验证">
                                </div>
                                <button type="submit" class="layui-btn" id="btnSendCode" name="btnSendCode" onclick="getCode()">获取验证码</button>
                            </div>
                    </div>
                </div>
                <div class="layui-tab-item " th:if="${0!=smsEnable}">
                    <div class="layui-form layui-form-pane">
                        <div class="layui-form-item">
                            <label for="phone" class="layui-form-label">手机号</label>
                            <div class="layui-input-inline">
                                <input type="text" id="phone" name="phone" required lay-verify="phone" placeholder="请输入您的手机号" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label for="verifyPhoneCode" class="layui-form-label">验证码</label>
                            <div class="layui-input-inline">
                                <input type="text" id="verifyPhoneCode" name="verifyPhoneCode" required lay-verify="required" autocomplete="off" class="layui-input" placeholder="请先点击下方人机验证">
                            </div>
                            <button type="submit" class="layui-btn" id="btnSendPhoneCode" name="btnSendPhoneCode" onclick="getPhoneCode()">获取验证码</button>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div id="bindBtn" style="width: 100px;height: 36px;">
                        <div class="vaptcha-init-main">
                            <div class="vaptcha-init-loading">
                                <a href="/" target="_blank">
                                    <img src="https://r.vaptcha.com/public/img/vaptcha-loading.gif" />
                                </a>
                                <span class="vaptcha-text">Vaptcha启动中...</span>
                            </div>
                        </div>
                    </div>
                </div>
                <div th:if="${section=='register'}" class="layui-form-item layui-form layui-form-pane">
                    <div class="layui-form-item">
                        <label for="pass" class="layui-form-label">设置密码</label>
                        <div class="layui-input-inline">
                            <input type="password" id="pass" name="pass" placeholder="请输入6到16个字符" required lay-verify="required" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label for="repass" class="layui-form-label">确认密码</label>
                        <div class="layui-input-inline">
                            <input type="password" id="repass" name="repass" placeholder="请再次输入您的密码" required lay-verify="required" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <button type="button" class="layui-btn" onclick="login()">提交</button>
                    <span style="padding-left:20px;">
                    <th:block th:if="${section == 'login'}"><a href="/sso/register">尚无账号?去注册</a> | <a href="/sso/reset">忘记密码?去重置</a></th:block>
                    <a th:if="${section == 'register'}" href="/sso/login">已有账号?去登陆</a>
                </span>
                </div>
                <div class="layui-form-item fly-form-app">
                    <span th:text="${'或者使用社交账号'+sectionName}"></span>
                    <a th:href="${'https://graph.qq.com/oauth2.0/authorize?client_id='+@environment.getProperty('qq.client.id')+'&redirect_uri='+@environment.getProperty('qq.redirect.uri')+'&response_type=code&state=1'}" onclick="layer.msg('正在通过QQ登入', {icon:16, shade: 0.1, time:0})" class="iconfont icon-qq html5plus-hide" title="QQ登入"></a>
                    <a th:href="${'https://api.weibo.com/oauth2/authorize?client_id='+@environment.getProperty('weibo.client.id')+'&redirect_uri='+@environment.getProperty('weibo.redirect.uri')+'&response_type=code&state=1&scope=all'}" onclick="layer.msg('正在通过微博登入', {icon:16, shade: 0.1, time:0})" class="iconfont icon-weibo html5plus-hide" title="微博登入"></a>
                    <a href="javascript:authLoginQq();" class="iconfont icon-qq html5plus-display" title="QQ登入" style="display: none"></a>
                    <a href="javascript:authLoginWeibo();" class="iconfont icon-weibo html5plus-display" title="微博登入" style="display: none"></a>
                    <a th:href="${'https://openapi.baidu.com/oauth/2.0/authorize?client_id='+@environment.getProperty('baidu.client.id')+'&redirect_uri='+@environment.getProperty('baidu.redirect.uri')+'&response_type=code&state=1'}" onclick="layer.msg('正在通过百度登入', {icon:16, shade: 0.1, time:0})" class="iconfont" title="百度登入"><img src="/images/baidu120c.png" style="height: 26px"></a>
                    <a th:href="${'https://github.com/login/oauth/authorize?client_id='+@environment.getProperty('github.client.id')+'&redirect_uri='+@environment.getProperty('github.redirect.uri')+'&scope=user&state=1'}" onclick="layer.msg('正在通过GITHUB登入', {icon:16, shade: 0.1, time:0})" class="iconfont" title="GITHUB登入"><img src="/images/github120c.png" style="height: 26px"></a>
                </div>

            </div>
        </div>
    </div>
</div>

<th:block th:insert="~{common/footer :: foot}"></th:block>
<script src="http://pv.sohu.com/cityjson?ie=utf-8"></script>
<script>
    layui.cache.page = 'user';
    layui.cache.user = {
        username: '游客'
        ,uid: -1
        ,avatar: '/images/avatar/00.jpg'
        ,experience: 83
        ,sex: '男'
    };
    layui.config({
        version: "3.0.0"
        ,base: '/mods/'
    }).extend({
        fly: 'index'
    }).use('fly');
</script>
<script src="https://v.vaptcha.com/v3.js"></script>
<script type="text/javascript">
    aqq=null;
    aweibo=null;
    var auths = {};
    function getService(){
        plus.oauth.getServices(function(services){
            for(var i in services){
                auths[services[i].id]=services[i];
                //alert(services[i].id);
            }
            aqq = auths['qq'];
            aweibo=auths['sinaweibo'];
            //var aaa='qq';
            //alert("6666"+auths[aaa].id);
            authLogout();
        }, function(e){
            plus.nativeUI.alert("获取登录授权服务列表失败："+JSON.stringify(e));
        } );
    }

    function authorize(){
        if(!aqq.id){
            alert("当前环境不支持qq登录");
            plus.nativeUI.alert("当前环境不支持qq登录");
            return;
        }
        aqq.authorize(function(e){
            alert("授权成功："+JSON.stringify(e));
            plus.nativeUI.alert("授权成功："+JSON.stringify(e));
        }, function(e){
            alert("授权失败："+JSON.stringify(e));
            plus.nativeUI.alert("授权失败："+JSON.stringify(e));
        }, {scope:'get_user_info',state:'1',appid:'101859689',redirect_url:'https://niter.cn/callbackqq'});
        alert("222");
    }

    function authLoginQq(){
        if(!aqq){
            plus.nativeUI.alert("当前环境不支持QQ登录");
            return;
        }
        if(!aqq.authResult){
            aqq.login(function(e){
                //plus.nativeUI.alert("登录认证成功!");
                aqq.getUserInfo( function(e){
                    queryServer('qq');
                }, function(e){
                    plus.nativeUI.alert("获取用户信息失败： "+JSON.stringify(e));
                } );
            }, function(e){
                plus.nativeUI.alert("登录认证失败: "+JSON.stringify(e));
            },{scope:'get_user_info',state:'1',appid:'101859689',redirect_url:'https://niter.cn/callbackqq'});
        }else{
            //plus.nativeUI.alert("已经登录认证!");
            queryServer('qq');
        }
    }
    function authLoginWeibo(){
        if(!aweibo){
            plus.nativeUI.alert("当前环境不支持微博登录");
            return;
        }
        if(!aweibo.authResult){
            aweibo.login(function(e){
                //plus.nativeUI.alert("登录认证成功!");
                aweibo.getUserInfo( function(e){
                    queryServer('weibo');
                    }, function(e){
                    plus.nativeUI.alert("获取用户信息失败： "+JSON.stringify(e));
                } );

                //authLogout();
            }, function(e){
                plus.nativeUI.alert("登录认证失败: "+JSON.stringify(e));
            },{scope:'all',state:'1',appid:'2346150891',redirect_url:'https://niter.cn/callbackweibo'});
        }else{
            //plus.nativeUI.alert("已经登录认证!");
            queryServer('weibo');
        }
    }

    function authUserInfo(){
        if((!aqq)&&(!aweibo)){
            plus.nativeUI.alert("当前环境不支持qq与微博登录");
            return;
        }
        if(aqq.authResult){
            aqq.getUserInfo( function(e){
               // plus.nativeUI.alert("获取用户信息成功："+JSON.stringify(aqq.userInfo));
            }, function(e){
                plus.nativeUI.alert("获取用户信息失败： "+JSON.stringify(e));
            } );
        }else if(aweibo.authResult){
            aweibo.getUserInfo( function(e){
               // plus.nativeUI.alert("获取用户信息成功："+JSON.stringify(aweibo.userInfo));
            }, function(e){
                plus.nativeUI.alert("获取用户信息失败： "+JSON.stringify(e));
            } );
        }
        else {
            plus.nativeUI.alert("未登录认证!");
        }
    }
    function alertAuthService() {
        if(aqq){
            alert(JSON.stringify(aqq));
        }
        if(aweibo){
            alert(JSON.stringify(aweibo));
        }

    }
    function authLogout(){
        if((!aqq.authResult)&&(!aweibo.authResult)){
            //plus.nativeUI.alert("当前不需要退出");
            return;
        }
        if(aqq.authResult){
            aqq.logout(function(e){
                //plus.nativeUI.alert("注销登录认证成功!");
            }, function(e){
                //plus.nativeUI.alert("注销登录认证失败: "+JSON.stringify(e));
            });
        } else if(aweibo.authResult){
            aweibo.logout(function(e){
                //plus.nativeUI.alert("注销登录认证成功!");
            }, function(e){
                //plus.nativeUI.alert("注销登录认证失败: "+JSON.stringify(e));
            });
        }

    }

    function queryServer(service){
        if('weibo'==service) var sdata=JSON.stringify(aweibo);
        else if('qq'==service) var sdata=JSON.stringify(aqq);
       // alert("sdata"+sdata);
        $.ajax({
            type:"POST",
            url:"/api/oauthLogin",
            dataType:"json",
            contentType:"application/json",
            data:sdata,
            success:function(data){
                if(data.code==0){
                    alert("错误："+data.msg);
                }
                else if(data.code==200){
                    //alert(data.token);
                    swal({
                        title: "恭喜您!",
                        text: ""+data.msg,
                        icon: "success",
                    }).then((value) => {
                        window.location.href='/forum';
                });                }
                else alert("else:未知错误");
            },
            error:function(data){
                alert("error");
            }
        });
    }

    function plusReady(){
        getService();
        //authLogout();
    }
    if(window.plus){
        plusReady();
    }else{
        document.addEventListener('plusready',plusReady,false);
    }





</script>
<script type="text/javascript">
    var qrcodeStr = Math.random().toString(36).substr(2);
    function alertQrcode() {
        swal({
            title: "请扫描此二维码，授权登录!",
            text: "请打开手机APP，扩展-扫描二维码，失效请刷新",
            icon: "https://www.zhihu.com/qrcode?url=https://niter.cn/sso/appConfirm?qrcodeStr="+qrcodeStr,
        });
        var QrInterValObj; //timer变量，控制时间
        var QrCount = 30; //间隔函数，2秒执行1次
        var QrCurCount;
        QrInterValObj = window.setInterval(SetQrRemainTime, 2000); //启动计时器，2秒执行一次
        function SetQrRemainTime() {
            if (QrCurCount == 1) {
                window.clearInterval(QrInterValObj);//停止计时器
            }
            else {
                QrCurCount--;
                $.ajax({
                    type: "get",
                    url: "/sso/appConfirmResult",
                    ContentType: "application/json",
                    CacheControl: "no-cache",
                    data:{
                        qrcodeStr:qrcodeStr
                    },
                    //  dataType: "json",
                    success: function(data) {
                        if(data.success==1){
                            window.location.href='/registerorLoginWithMailisOk?token='+data.token;
                        }
                    },
                    error: function(msg) {
                        console.log(msg)
                    }
                })            }
        }
    }

</script>
<script type="text/javascript">
    token = '';
    ossType=[[${initOssType}]];
    userIp='';
    function setType(a){
        ossType=a;
    }
    function login() {
        if(token == '') {
            swal({
                title: "哎哟...",
                text: "请先完成人机验证再提交哦~",
                icon: "error",
                button: "确认",
            });
        }else{
            if(ossType==1){//手机验证码登录
                registerOrLoginWithPhone();            }
            if(ossType==2){//登录邮箱
                registerOrLoginWithMail();            }
            if(ossType==3){//密码登录
                loginWithPW();            }
            if(ossType==4){//登录QQ
                window.location='https://graph.qq.com/oauth2.0/authorize?client_id=101797776&redirect_uri=' + document.location.origin + '/callbackqq&sresponse_type=code&state=1' ;
            }
            if(ossType==5){//登录百度
                window.location='https://openapi.baidu.com/oauth/2.0/authorize?client_id=OhHUeQ1wGTGC8AuZ9TX1A5IW&response_type=code&redirect_uri='+ document.location.origin +'/callbackbaidu&state=1' ;
            }
            if(ossType==6){//登录github
                window.location='https://github.com/login/oauth/authorize?client_id=b6ecb208ce93f679a75a&redirect_uri=' + document.location.origin + '/callback&scope=user&state=1' ;
            }

            if(ossType==8){//微博登录
                window.location='https://api.weibo.com/oauth2/authorize?client_id=4162907344&response_type=code&redirect_uri=' + document.location.origin + '/callbackweibo&scope=all&state=1' ;
            }
        }


    }

    vaptcha({
        //配置参数
        vid: '[[${vaptcha_vid}]]', // 验证单元id
        type: 'click', // 展现类型 点击式
        container: '#bindBtn', // 按钮容器，可为Element 或者 selector
        scene:1,               //场景值02，即评论
        offline_server: '/validateOffline' //离线模式服务端地址
    }).then(function (vaptchaObj) {
        vaptchaObj6=vaptchaObj;
        vaptchaObj.listen('pass', function() {
            // 验证成功， 进行登录操作
            // console.log(vaptchaObj.getToken());
            //getCode();
            token=vaptchaObj.getToken();
            userIp=returnCitySN["cip"];
            console.log(userIp);
            $.ajax({
                type: "post",
                url: "/validate",
                ContentType: "application/json",
                CacheControl: "no-cache",
                data:{
                    scene:1,
                    //token:vaptchaObj.getToken(),
                    token:token,
                    ip:userIp
                },
                //  dataType: "json",
                success: function(data) {
                    if(data.success==1){
                        //成功
                       // console.log("成功"+token);
                    }
                    else if(data.success==0){
                        // alert(this.userIp)
                        swal({
                            title: ""+data.msg,
                            text: "您未能通过我们的第二次智能检测，请稍后再试或联系管理员",
                            icon: "error",
                            button: "确认",
                        });
                        //vaptchaObj.reset();
                    }
                },
                error: function(msg) {
                    console.log(msg)
                }
            });
        })
        vaptchaObj.listen('close', function() {
            //验证弹窗关闭触发
            swal({
                title: "哎哟...",
                text: "您关闭了验证哦",
                icon: "error",
                button: "确认",
            });
        })
        vaptchaObj.render()// 调用验证实例 vaptchaObj 的 render 方法加载验证按钮
    })
</script>
<script type="text/javascript">
    isValid=1;//是否可以发送验证码
    var InterValObj; //timer变量，控制时间
    var count = 60; //间隔函数，1秒执行
    var curCount;//当前剩余秒数
    function getCode() {
        //console.log("token2:"+token);
        if (isValid == 0) {
            swal({
                title: "哎哟...",
                text: "您刚刚提交过了哦，请等待60s后再提交哦~",
                icon: "error",
                button: "确认",
            });
        }else if(token == ''||vaptchaObj6==null) {
            swal({
                title: "哎哟...",
                text: "请先完成人机验证再提交哦~",
                icon: "error",
                button: "确认",
            });
        } else {
            var username = $("#username").val();
            var mail = $("#mail").val();
            var reg = new RegExp("^[a-z0-9A-Z]+[- | a-z0-9A-Z . _]+@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-z]{2,}$");
            if(!reg.test(mail)){
                layer.msg("邮箱不合法");
                return false;
            }
            isValid == 0
            curCount = count;
            $("#btnSendCode").attr("disabled", "true");
            $("#btnSendCode").text(curCount + "秒后重新发送");
            $("#btnSendCode").removeAttr("onclick");
            InterValObj = window.setInterval(SetRemainTime, 1000); //启动计时器，1秒执行一次

            //  console.log(obj2.getToken());

//if(phone.length!=11) {sweetAlert("哎哟...", "手机号长度不合法！请重新输入!", "error");return;}
            $.post('/mail/getMailCode', {
                mail:mail,
                username:username,
                token:token,
                ip:userIp
            }, function(result){
                if (result.code == 2030) {
                    swal({
                        title: "哎哟...",
                        text: "" + result.message,
                        icon: "error",
                        button: "确认",
                    });
                    //vaptchaObj.reset();
                } else {
                    //sessionStorage.setItem("code", result.message);
                    sweetAlert("请耐心等待", ""+result.message, "info");
                    $('#mail').attr("disabled", "disabled");

                }
            });
        }
    }

    function SetRemainTime() {
        if (curCount == 1) {
            isValid == 1
            window.clearInterval(InterValObj);//停止计时器
            $("#btnSendCode").removeAttr("disabled");//启用按钮
            $("#btnSendCode").attr("onclick","getCode();");
            $("#btnSendCode").text("获取验证码");
        }
        else {
            curCount--;
            $("#btnSendCode").text(curCount + "秒后重新发送");
        }
    }

    function registerOrLoginWithMail(){
        var verifyCode = $("#verifyCode").val();
        var mail = $("#mail").val();
        var pass = $("#pass").val();
        var repass = $("#repass").val();
        if(pass==null||repass==null) pass="null";
        else if(pass!=repass){
                swal("注册失败!", "两次密码不一致!", "warning");
                return false;
        }else if(pass.length<6||pass.length>16){
            swal("注册失败!", "当前密码长度不满足要求!", "warning");
            return false;
        }
       // if(verifyCode==sessionStorage.getItem("code")){//客户端第一次校验
            $.post('/api/sso/mail/registerOrLoginWithMail', {
                mail:mail,
                code:verifyCode,
                password:pass
            }, function(result){
                if (result.code == 200) {
                    swal({
                        title: "恭喜您!",
                        text: "您已经成功登陆啦!",
                        icon: "success",
                    }).then((value) => {
                        window.location.href='/forum';
                });
                } else {
                    swal({
                        title: "注册/登录失败!",
                        text: ""+result.message,
                        icon: "error",
                        button: "确认",
                    });
                }
            });
    }
</script>
<script type="text/javascript">
    isValid=1;//是否可以发送验证码
    var InterValObj; //timer变量，控制时间
    var count = 60; //间隔函数，1秒执行
    var curCount;//当前剩余秒数
    function getPhoneCode() {
        var phone = $("#phone").val();{
            if(phone.length!=11||!(/^1[3456789]\d{9}$/.test(phone))){
                swal({
                    title: "哎哟...",
                    text: "手机号码有误，请重填",
                    icon: "error",
                    button: "确认",
                });
                return;
            }
        }
        if (isValid == 0) {
            swal({
                title: "哎哟...",
                text: "您刚刚提交过了哦，请等待60s后再提交哦~",
                icon: "error",
                button: "确认",
            });
        }else if(token == ''||vaptchaObj6==null) {
            swal({
                title: "哎哟...",
                text: "请先完成人机验证再提交哦~",
                icon: "error",
                button: "确认",
            });
        } else {
            isValid == 0
            curCount = count;
            $("#btnSendPhoneCode").attr("disabled", "true");
            $("#btnSendPhoneCode").text(curCount + "秒后重新发送");
            $("#btnSendPhoneCode").removeAttr("onclick");
            InterValObj = window.setInterval(SetRemainTimeforPhone, 1000); //启动计时器，1秒执行一次

            //  console.log(obj2.getToken());
            // var username = $("#username").val();
//if(phone.length!=11) {sweetAlert("哎哟...", "手机号长度不合法！请重新输入!", "error");return;}
            $.post('/api/sso/phone/getPhoneCode', {
                phone:phone,
                token:token,
                ip:userIp
            }, function(result){
                if (result.code == 2032) {
                    swal({
                        title: "哎哟，验证码发送失败",
                        text: "" + result.message,
                        icon: "error",
                        button: "确认",
                    });
                    //vaptchaObj.reset();
                } else {
                    msg_id = result.message;
                    sweetAlert("请耐心等待", "验证码已发送成功!", "info");
                    $('#phone').attr("disabled", "disabled");

                }
            });
        }
    }

    function SetRemainTimeforPhone() {
        if (curCount == 1) {
            isValid == 1
            window.clearInterval(InterValObj);//停止计时器
            $("#btnSendPhoneCode").removeAttr("disabled");//启用按钮
            $("#btnSendPhoneCode").attr("onclick","getPhoneCode();");
            $("#btnSendPhoneCode").text("获取验证码");
        }
        else {
            curCount--;
            $("#btnSendPhoneCode").text(curCount + "秒后重新发送");
        }
    }

    function registerOrLoginWithPhone(){
        var verifyPhoneCode = $("#verifyPhoneCode").val();
        var phone = $("#phone").val();
        var pass = $("#pass").val();
        var repass = $("#repass").val();
        if(pass==null) pass="null";
        else if(pass!=repass){
            swal("注册失败!", "两次密码不一致!", "warning");
            return false;
        }else if(pass.length<6||pass.length>16){
            swal("注册失败!", "当前密码长度不满足要求!", "warning");
            return false;
        }
       // console.log("code:"+verifyPhoneCode+" msg_id:"+msg_id+" phone:"+phone)
        $.post('/api/sso/phone/ValidCode', {
            msg_id:msg_id,
            code:verifyPhoneCode,
            phone:phone,
            state:2,
            password:pass
        }, function(result){
            if (result.code == 200) {
                swal({
                    title: "恭喜您!",
                    text: "您已经成功登陆啦!",
                    icon: "success",
                }).then((value) => {
                    window.location.href='/forum';
            });
            } else {
                swal({
                    title: "注册/登录失败!",
                    text: ""+result.message,
                    icon: "error",
                    button: "确认",
                });
            }
        });
    }

</script>
<script type="text/javascript">
    function loginWithPW(){
        var phoneorMail = $("#phoneorMail").val();
        var password = $("#password").val();
        var type=1;//1为手机号，2为邮箱号
        if(password.length<6||password.length>16){
            swal("登录失败!", "当前密码长度不满足要求!", "warning");
            return false;
        }

        var mailReg = new RegExp("^[a-z0-9A-Z]+[- | a-z0-9A-Z . _]+@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-z]{2,}$");
        if((!mailReg.test(phoneorMail))){//邮箱不合法
            if(phoneorMail.length!=11||!(/^1[3456789]\d{9}$/.test(phoneorMail))){//手机不合法
                swal({
                    title: "哎哟...",
                    text: "你输入的手机号或者邮箱号有误，请重填",
                    icon: "warning",
                    button: "确认",
                });
                return;
            }

        }else {//邮箱合法
            type=2;
        }

        $.ajax({
            type:"POST",
            url:"/api/sso/login",
           // dataType:"json",
           // contentType:"application/json",
            data:{
                "name": phoneorMail
                ,"password":password
                ,"type":type
            },
            success:function(res){
                if(res.code==200) {
                    swal({
                        title: "恭喜您!",
                        text: "您已经成功登陆啦!",
                        icon: "success",
                    }).then((value) => {
                        window.location.href='/forum';
                });
                }else if(res.code==2041){
                    swal({
                        title: "登录失败!",
                        text: ""+res.message,
                        icon: "error",
                        buttons: {
                            reset: {
                                text: "重置密码",
                                value: "reset",
                            },
                            cancel: "再试试"
                        },
                        //dangerMode: true,
                    })
                        .then((value) => {
                        if (value=='reset') {
                        window.location.href='/sso/reset';
                        }
                });
                    //swal("Oh,no!", ""+res.message, "error");
                }
                else swal("Oh,no!", ""+res.message, "error");
            },
            error:function(XMLHttpRequest, textStatus, errorThrown){
                swal(textStatus, "错误："+XMLHttpRequest.status, "error");
            }
        });
    }
</script>
</body>
</html>